package indi.jp.project.center.controller;

import indi.jp.project.center.entity.Task;
import indi.jp.project.center.service.TaskService;
import indi.jp.project.core.entity.Datagrid;
import indi.jp.project.core.entity.JsonResult;
import indi.jp.project.core.util.SimpleEntityUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import java.sql.SQLException;

@RestController
@RequestMapping("/center/task")
public class TaskController {

    @Autowired
    private TaskService taskService;

    @GetMapping("/queryGrid")
    @ResponseBody
    public JsonResult queryGrid(@ModelAttribute Task entity, HttpServletRequest request) {
        SimpleEntityUtil<Task> simpleEntityUtil = new SimpleEntityUtil<>();
        entity = simpleEntityUtil.setBaseEntity(entity, request);
        try {
            Datagrid<Task> datagrid = taskService.queryGrid(entity);
            return JsonResult.success(datagrid);
        } catch (SQLException e) {
            e.printStackTrace();
            return JsonResult.error();
        }
    }
}
